<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('实验项目列表')" />
    <!-- 若依表格样式+分页组件 -->
    <link th:href="@{/plugins/layui/css/layui.css}" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <!-- 搜索栏 -->
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>实验项目名称：</label>
                            <input type="text" name="projectName" placeholder="请输入实验名称" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <!-- 功能按钮栏 -->
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="college:experimentProject:add">
                <i class="fa fa-plus"></i> 添加实验项目
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="college:experimentProject:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="college:experimentProject:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="college:experimentProject:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <!-- 实验项目表格 -->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>

<!-- 引入若依公共JS -->
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    // 权限控制标记
    var editFlag = [[${@permission.hasPermi('college:experimentProject:edit')}]];
    var removeFlag = [[${@permission.hasPermi('college:experimentProject:remove')}]];
    // 课程安排ID（从列表页面跳转携带）
    var arrangementId = [[${arrangementId}]];
    // 请求前缀
    var prefix = ctx + "college/experimentProject";

    $(function() {
        var options = {
            url: prefix + "/listData",
            createUrl: prefix + "/add/" + arrangementId,
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export/" + arrangementId,
            modalName: "实验项目",
            queryParams: function(params) {
                return {
                    pageSize: params.limit,
                    pageNum: params.offset / params.limit + 1,
                    arrangementId: arrangementId,
                    projectName: $("input[name='projectName']").val(),
                    experimentNumber: $("input[name='experimentNumber']").val()
                };
            },
            columns: [
                {
                    checkbox: true,
                    align: 'center'
                },
                {
                    field: 'projectId',
                    title: '实验项目ID',
                    visible: false
                },
                {
                    field: 'experimentNumber',
                    title: '实验序号',
                    align: 'center'
                },
                {
                    field: 'projectName',
                    title: '实验名称',
                    align: 'center'
                },
                {
                    field: 'purpose',
                    title: '实验目的',
                    align: 'center'
                },
                {
                    field: 'content',
                    title: '实验内容',
                    align: 'center'
                },
                {
                    field: 'experimentPeriod',
                    title: '实验学时',
                    align: 'center'
                },
                {
                    field: 'experimentTime',
                    title: '实验时间',
                    align: 'center'//,
                    // formatter: function(value) {
                    //     return value ? moment(value).format('YYYY-MM-DD HH:mm') : '-';
                    // }
                },
                {
                    field: 'deadline',
                    title: '截止日期',
                    align: 'center'//,
                    // formatter: function(value) {
                    //     return value ? moment(value).format('YYYY-MM-DD HH:mm') : '-';
                    // }
                },
                {
                    field: 'attachment',
                    title: '附件',
                    align: 'center',
                    formatter: function(value) {
                        if (!value || value === '') return '-';
                        var html = '';
                        var paths = value.split(',');
                        paths.forEach(function(path) {
                            var fileName = path.substring(path.lastIndexOf('/') + 1);
                            html += '<a href="' + [[${@config.getKey("ruoyi.upload.url")}]] + path + '" target="_blank">' + fileName + '</a><br>';
                        });
                        return html;
                    }
                },
                // {
                //     field: 'createTime',
                //     title: '创建时间',
                //     align: 'center'//,
                //     // formatter: function(value) {
                //     //     return value ? moment(value).format('YYYY-MM-DD HH:mm') : '-';
                //     // }
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.projectId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.projectId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });
</script>
</body>
</html>